package KK.Controls.Tips
{ 
	import KK.Controls.Skin.SkinSheet;
	import KK.System.System;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class BaseBox extends Sprite
	{
		
		static private var MINWIDTH:int;
		static private var MINHEIGHT:int;
		
		protected var sheet:SkinSheet;
		
		private var MaxWidth:int=300;
		private var MaxHeight:int=300;
		
		private var background:Bitmap;
		private var source:BitmapData;
		
		private var size:Point;//大小 
		private var scale9Rect:Vector.<Rectangle>;
		public function BaseBox(MaxWidth:int,MaxHeight:int)
		{
			//TODO: implement function
			super();
			this.MaxWidth=MaxWidth;
			this.MaxHeight=MaxHeight;
			init();
		}
		/**
		 * 初始化  
		 * 
		 */
		private function init():void{
			background=new Bitmap;
			size=new Point();
			
			
			addChild(background);
			background.bitmapData=new BitmapData(MaxWidth,MaxHeight,true,0);
			
		}
		
		/**
		 * 设置源 
		 * @param value
		 * 
		 */
		public function set Skin(value:BitmapData):void{
			source=value;
			MINWIDTH=value.width;
			MINHEIGHT=value.height;
			sheet=new SkinSheet(source.width,source.height);
			setSize(64,64);
		}
		
		
		
		/**
		 * 设置大小  
		 * @param width
		 * @param height
		 * 
		 */
		public function setSize(width:int,height:int):void{
			size.x=width<MINWIDTH?MINWIDTH:width;
			size.y=height<MINHEIGHT?MINHEIGHT:height;
			
			size.x=width>MaxWidth?MaxWidth:size.x;
			size.y=height>MaxHeight?MaxHeight:size.y;
			
			
			
			
			sheet.setSize(size,new Point);
			
//			scale9Rect=ConveyScale9(size,sheet.Area,new Point());
			scale9Rect=sheet.targetRect;
			resizeBackground();
		}
		

		 
		
		/**
		 * 清除背景  
		 * 
		 */
		private function clearBackground():void{
			background.bitmapData.fillRect(new Rectangle(0,0,MaxWidth,MaxHeight),0);
		}
		
		/**
		 * 重绘背景  
		 * 
		 */
		protected function resizeBackground():void{
			clearBackground();
			
			
			System.FillVectorBitmapData(source,background.bitmapData,sheet.Area,scale9Rect);
			
		}
		
		
	}
}